package it.polimi.swKnights.SWIMv2.ejb.entityBeans;

import java.io.Serializable;
import javax.persistence.*;

/**
 * Entity implementation class for Entity: ReceivedMessages
 * 
 */
@Entity
@IdClass(ReceivedMessagesPK.class)
public class ReceivedMessages implements Serializable
{
	@Id
	@Column(name = "messageID", insertable = false, updatable = false)
	private int messageID;

	@Id
	@Column(name = "recipient", insertable = false, updatable = false)
	private String recipient;
	
	private boolean messageRead;
	
	@ManyToOne
	@JoinColumn(name = "messageID", insertable = false, updatable = false)
	private PrivateMessage message;
	
	@ManyToOne
	@JoinColumn(name = "recipient", insertable = false, updatable = false)
	private RegisteredUser recipientUser;
	

	private static final long serialVersionUID = 1L;

	/*
	 * Constructors
	 */

	public ReceivedMessages()
	{
		super();
	}
	
	public ReceivedMessages(PrivateMessage message, RegisteredUser recipient)
	{
		super();
		this.messageID = message.getId();
		this.recipient = recipient.getUserName();
		this.messageRead = false;
	}
	
	/*
	 * Getters and setters
	 */

	public boolean isMessageRead()
	{
		return messageRead;
	}

	public void setMessageRead(boolean messageRead)
	{
		this.messageRead = messageRead;
	}

	public String getRecipient()
	{
		return this.recipient;
	}

}
